package demo;

import javax.jms.JMSException;
import javax.jms.TextMessage;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author brizat
 */
@Component
public class JMSReceiver {

    @Autowired
    private RuntimeService runtimeService;

    public void reciveMessage(TextMessage message) throws JMSException {
        message.acknowledge();
        String body = message.getText();
        String executionId = message.getStringProperty("processInstanceId");

        Execution singleResult = runtimeService.createExecutionQuery()
                .messageEventSubscriptionName("testMessage")
                .processInstanceId(executionId)
                .singleResult();

        runtimeService.messageEventReceived("testMessage", singleResult.getId());
    }

}
